package com.mall.web.controller.order.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mall.order.model.dto.OrderTransDto;
import com.mall.order.model.vo.OrderTransVo;
import com.mall.order.service.IOrderTransService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.common.core.page.TableDataInfo;

/**
 * 商城订单微信交易Controller
 */
@RestController
@RequestMapping("/admin/order/orderTrans")
public class AdminOrderTransController extends BaseController
{
    @Autowired
    private IOrderTransService orderTransService;

    /**
     * 查询商城订单微信交易列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderTrans:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderTransDto orderTransDto)
    {
        startPage();
        List<OrderTransVo> list = orderTransService.selectOrderTransList(orderTransDto);
        return getDataTable(list);
    }

    /**
     * 导出商城订单微信交易列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderTrans:export')")
    @Log(title = "商城订单微信交易", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderTransDto orderTransDto)
    {
        List<OrderTransVo> list = orderTransService.selectOrderTransList(orderTransDto);
        ExcelUtil<OrderTransVo> util = new ExcelUtil<OrderTransVo>(OrderTransVo.class);
        util.exportExcel(response, list, "商城订单微信交易数据");
    }

    /**
     * 获取商城订单微信交易详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderTrans:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderTransService.selectOrderTransById(id));
    }

    /**
     * 新增商城订单微信交易
     */
    @PreAuthorize("@ss.hasPermi('order:orderTrans:add')")
    @Log(title = "商城订单微信交易", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderTransDto orderTransDto)
    {
        return toAjax(orderTransService.insertOrderTrans(orderTransDto));
    }

    /**
     * 修改商城订单微信交易
     */
    @PreAuthorize("@ss.hasPermi('order:orderTrans:edit')")
    @Log(title = "商城订单微信交易", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderTransDto orderTransDto)
    {
        return toAjax(orderTransService.updateOrderTrans(orderTransDto));
    }

    /**
     * 删除商城订单微信交易
     */
    @PreAuthorize("@ss.hasPermi('order:orderTrans:remove')")
    @Log(title = "商城订单微信交易", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderTransService.deleteOrderTransByIds(ids));
    }
}
